<?php
/**
 * @package		Joomla.Site
 * @subpackage	com_users
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

jimport('joomla.application.component.view');

/**
 * Registration view class for Users.
 *
 * @package		Joomla.Site
 * @subpackage	com_users
 * @since		1.6
 */
class UsersViewRegistration extends JView
{
	protected $data;
	protected $form;
	protected $params;
	protected $state;

	/**
	 * Method to display the view.
	 *
	 * @param	string	The template file to include
	 * @since	1.6
	 */
	public function display($tpl = null)
	{
		$layout = JRequest::getCmd('layout', 'layout');		
		switch ($layout){
			case "city":
				$this->listcity();
				break;
			case "activation":
				$this->activatioin();
				break;
			case "complete":
				$this->complete();
				break;
			default:
				$this->defautlForm();
				break;
		}
	}
	function listcity()
  	{ 
		global $mainframe;
		$country_id=JRequest::getVar( 'country_id');
//		$model = $this->getModel('register');
     	$model = $this->getModel('Registration');
 		
     	$cities = $model->getCities( $country_id );
//     	print_r($cities);
//     	echo $cities;	
		echo "<div id='cityData'>".$this->cities 	= JHTML::_('select.genericlist',   $cities, 'jform[city_id]', 'class="dropdown-box" size="1" ', 'value', 'text', "" )."</div>";
		           	
  	}
	public function activatioin(){
		require_once JPATH_COMPONENT.DS.'views'.DS.'registration'.DS.'tmpl'.DS.'activation.php';
	}
	
	public function complete(){
		require_once JPATH_COMPONENT.DS.'views'.DS.'registration'.DS.'tmpl'.DS.'completes.php';		
	}

	public function defautlForm(){
		// Get the view data.		
		$this->data		= $this->get('Data');
		$this->form		= $this->get('Form');
		$this->state	= $this->get('State');
		$this->params	= $this->state->get('params');
		//print_r($this->data);exit;
		$model = $this->getModel('Registration');
		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
			JError::raiseError(500, implode('<br />', $errors));
			return false;
		}		
		// Check for layout override
		$active = JFactory::getApplication()->getMenu()->getActive();
		if (isset($active->query['layout'])) {
			$this->setLayout($active->query['layout']);			
		}
		
		$countries = $model->getCountries();			
		
		$countryList[] 		= JHTML::_('select.option',  '', JText::_( '' ) );
		if (sizeof($countries)){
			foreach( $countries as $obj )
			{
				$countryList[] = JHTML::_('select.option',  $obj->value, JText::_( $obj->text ) );
			}
			$this->countries 	= JHTML::_('select.genericlist',   $countryList, 'jform[country_code]', 'class="dropdown-box countryCode" size="1"', 'value', 'text', "" );
		}
		
		
		
//		$cities = $model->getCities();		
		$cityList[] 		= JHTML::_('select.option',  '', JText::_( '' ) );	
		$this->cities 	= JHTML::_('select.genericlist',   $cityList, 'jform[city_id]', 'class="dropdown-box1" size="1" ', 'value', 'text', "" );
		
		$education = $model->getEducation();	
		$educationList[] 		= JHTML::_('select.option',  '', JText::_( '' ) );
		if (sizeof($education)){
			foreach( $education as $obj )
			{
				$educationList[] = JHTML::_('select.option',  $obj->value, JText::_( $obj->text ) );
			}
			$this->education 	= JHTML::_('select.genericlist',   $educationList, 'jform[education_id]', 'class="dropdown-box" size="1" ', 'value', 'text', "" );
		}	
		
		$categories = $model->getCategories();			
		$categoryList[] 		= JHTML::_('select.option',  '', JText::_( '' ) );
		if (sizeof($categories)){
			foreach( $categories as $obj )
			{
				$categoryList[] = JHTML::_('select.option',  $obj->value, JText::_( $obj->text ) );
			}
			$this->categories 	= JHTML::_('select.genericlist',   $categoryList, 'jform[industry_id]', 'class="dropdown-box" size="1" ', 'value', 'text', "" );
		}
		
		//Escape strings for HTML output
		$this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx'));

		$this->prepareDocument();

		parent::display($tpl);
	}
	/**
	 * Prepares the document.
	 *
	 * @since	1.6
	 */
	protected function prepareDocument()
	{
		$app		= JFactory::getApplication();
		$menus		= $app->getMenu();
		$title 		= null;

		// Because the application sets a default page title,
		// we need to get it from the menu item itself
		$menu = $menus->getActive();
		if ($menu) {
			$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
		} else {
			$this->params->def('page_heading', JText::_('COM_USERS_REGISTRATION'));
		}

		$title = $this->params->get('page_title', '');
		if (empty($title)) {
			$title = $app->getCfg('sitename');
		}
		elseif ($app->getCfg('sitename_pagetitles', 0) == 1) {
			$title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
		}
		elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
			$title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
		}
		$this->document->setTitle($title);

		if ($this->params->get('menu-meta_description'))
		{
			$this->document->setDescription($this->params->get('menu-meta_description'));
		}

		if ($this->params->get('menu-meta_keywords'))
		{
			$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
		}

		if ($this->params->get('robots'))
		{
			$this->document->setMetadata('robots', $this->params->get('robots'));
		}
	}
}
